var forecast = new Vue({
	el: '#forecast',
	data: {
		display: false
	}
});


function caculate(){

}


var forecasting = new Vue({
	el: '#myModal',
	created: function(){
		for(key in this.history){
			var total = this.history[key].a[0] + this.history[key].b[0] +this.history[key].c[0]+this.history[key].d[0];
			this.history[key].b[1] = (this.history[key].b[0]/total*100).toFixed(2);
			this.history[key].a[1] = (this.history[key].a[0]/total*100).toFixed(2);;
			this.history[key].c[1] = (this.history[key].c[0]/total*100).toFixed(2);;
			this.history[key].d[1] = (this.history[key].d[0]/total*100).toFixed(2);;
		}

		for(key in this.history2){
			for(key2 in this.history2[key]){
				var t = this.history2[key][key2];
				t.d = (1 - t.a - t.b - t.c).toFixed(3);
			}
		}
 		console.log('haha--------');
 		console.log(this.history2.a.liuhe.d);

 		//预测开始 liuhe:a xixi:c
 		var a,b,c,d;

 		a = //this.history2.a.liuhe.a * 
 			this.history2.a.liuhe.b * 
 			//this.history2.a.liuhe.c * 
 			//this.history2.a.liuhe.d * 
 			//this.history2.a.xixi.a * 
 			//this.history2.a.xixi.b * 
 			this.history2.a.xixi.c * 
 			//this.history2.a.xixi.d * 
 			this.history.tianmu.a[1]/100; 

 		b = //this.history2.b.liuhe.a * 
 			this.history2.b.liuhe.b * 
 			//this.history2.b.liuhe.c * 
 			//this.history2.b.liuhe.d * 
 			//this.history2.b.xixi.a * 
 			//this.history2.b.xixi.b * 
 			this.history2.b.xixi.c * 
 			//this.history2.b.xixi.d * 
 			this.history.tianmu.b[1]/100; 

 		c = //this.history2.c.liuhe.a * 
 			this.history2.c.liuhe.b * 
 			//this.history2.c.liuhe.c * 
 			//this.history2.c.liuhe.d * 
 			//this.history2.c.xixi.a * 
 			//this.history2.c.xixi.b * 
 			this.history2.c.xixi.c * 
 			//this.history2.c.xixi.d * 
 			this.history.tianmu.c[1]/100; 

 		d = //this.history2.d.liuhe.a * 
 			this.history2.d.liuhe.b * 
 			//this.history2.d.liuhe.c * 
 			//this.history2.d.liuhe.d * 
 			//this.history2.d.xixi.a * 
 			//this.history2.d.xixi.b * 
 			this.history2.d.xixi.c * 
 			//this.history2.d.xixi.d * 
 			this.history.tianmu.d[1]/100;

 		var tttt = a + b + c + d;

 		this.res.a = (a/tttt*100).toFixed(2);
 		this.res.b = (b/tttt*100).toFixed(2);
 		this.res.c = (c/tttt*100).toFixed(2);
 		this.res.d = (d/tttt*100).toFixed(2);
 		var _this = this;
 		//预测结束
 		$('#shit').highcharts({
		    chart: {
		        type: 'pie',
		        options3d: {
		            enabled: true,
		            alpha: 45,
		            beta: 0
		        }
		    },
		    title: {
		        text: ''
		    },
		    tooltip: {
		        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
		    },
		    plotOptions: {
		        pie: {
		            allowPointSelect: true,
		            cursor: 'pointer',
		            depth: 35,
		            dataLabels: {
		                enabled: true,
		                format: '{point.name}'
		            }
		        }
		    },
		    colors:['#FF3300', '#FF9900', '#66CC00', '#669900'],
		    series: [{
		        type: 'pie',
		        name: '',
		        data: [
		            ['无法通行',   parseFloat(_this.res.a)],
		            ['拥堵',       parseFloat(_this.res.b)],
		            {
		                name: '正常',
		                y: parseFloat(_this.res.c),
		                sliced: true,
		                selected: true
		            },
		            ['畅通',    parseFloat(_this.res.d)] 
		        ]
		    }]
		});


	},
	data: {
		res: {
			a: 0,
			b: 0,
			c: 0,
			d: 0
		},
		history: {
			tianmu:{
				name: '天目山路',
				a: [35, 0],
				b: [68, 0],
				c: [124,0],
				d: [33,0]
			},			 
			liuhe:{
				name: '留和路',
				a: [42,0],
				b: [34,0],
				c: [27,0],
				d: [12,0]
			},
			xixi:{
				name: '西溪路',
				a: [12,0],
				b: [52,0],
				c: [69,0],
				d: [17,0]
			}
		},
		history2: {//天目山路各种路况下的其它路概率
			a: {
				liuhe: {
	 				a: 0.602,
					b: 0.224,
					c: 0.135,
					d: 0
	 			},
	 			xixi: {
	 				a: 0.42,
					b: 0.334,
					c: 0.235,
					d: 0
	 			}
			},
			b: {
				liuhe: {
	 				a: 0.223,
					b: 0.445,
					c: 0.284,
					d: 0
	 			},
	 			xixi: {
	 				a: 0.123,
					b: 0.368,
					c: 0.364,
					d: 0
	 			}
			},
			c: {
				liuhe: {
	 				a: 0.056,
					b: 0.187,
					c: 0.505,
					d: 0
	 			},
	 			xixi: {
	 				a: 0.068,
					b: 0.213,
					c: 0.624,
					d: 0
	 			}
			},
			d: {
				liuhe: {
	 				a: 0.024,
					b: 0.067,
					c: 0.758,
					d: 0
	 			},
	 			xixi: {
	 				a: 0.035,
					b: 0.089,
					c: 0.64,
					d: 0
	 			}
			}
 			 
		} 
	}
});



 



module.exports = forecast;